package teacher.dao;

import teacher.entity.Teacher;
import util.MysqlUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TeacherDao {

    public void teachercRevise() {
        try {
            Statement jbdc = MysqlUtil.JBDC();
            String sql = "select * from teachercrevise";
            ResultSet resultSet = jbdc.executeQuery(sql);
            while(resultSet.next()){
                String teacherName = resultSet.getString("teacher_name");
                int teacherId = resultSet.getInt("teacher_id");
                int teacherAge = resultSet.getInt("teacher_age");
                String teacherSex = resultSet.getString("teacher_sex");
                String teacherSubject = resultSet.getString("teacher_subject");
                String teacherClass = resultSet.getString("teacher_class");
                System.out.println("输出");
                System.out.println("姓名:"+teacherName);
                System.out.println("id:"+teacherId);
                System.out.println("年龄:"+teacherAge);
                System.out.println("性别："+teacherSex);
                System.out.println("科目："+teacherSubject);
                System.out.println("班级："+teacherClass);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    public void teachercp() {
        try {
            Statement jbdc = MysqlUtil.JBDC();
            String sql = "select * from teachercp";
            ResultSet resultSet = jbdc.executeQuery(sql);
            while(resultSet.next()){
                String teacherSubject = resultSet.getString("teacher_subject");
                String teacherTime= resultSet.getString("teacher_time");
                String teacherClass = resultSet.getString("teacher_class");
                String teacherLock = resultSet.getString("teacher_lock");
                System.out.println("输出");
                System.out.println("上课科目:"+teacherSubject);
                System.out.println("上课时间:"+teacherTime);
                System.out.println("上课班级:"+teacherClass);
                System.out.println("上课地点:"+teacherLock);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    public void teachercStudent() {
        try {
            Statement jbdc = MysqlUtil.JBDC();
            String sql = "select * from teachercstudent";
            ResultSet resultSet = jbdc.executeQuery(sql);
            while(resultSet.next()){
                String studentName = resultSet.getString("student_name");
                int studentCj= resultSet.getInt("student_cj");
                String studentClass = resultSet.getString("student_class");
                String studentSex = resultSet.getString("student_sex");
                System.out.println("  ");
                System.out.print("学生姓名:"+studentName);
                System.out.print("学生成绩:"+studentCj);
                System.out.print("学生班级:"+studentClass);
                System.out.print("学生性别:"+studentSex);
                System.out.println("  ");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    public void teachercs(Teacher teacher) {
        try {
            Statement jbdc = MysqlUtil.JBDC();
            String sql = "update teachercstudent set student_name=" + "\"" + teacher.getStudentName() + "\",student_cj="
                    + "\"" + teacher.getStudentCj()+ "\"" + "where student_id =" + teacher.getStudentId();
            boolean execute = jbdc.execute(sql);
            System.out.println("修改成功");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
